﻿using Assets.Scripts.DL.Consts;
using Assets.Scripts.DL.Mgrs;
using JetBrains.Annotations;
using UnityEngine;

public class PlayerAirTick : PlayerBaseState {
	bool _loopAnimStart;
	public PlayerAirTick(PlayerController controller, PlayerStateEnum stateName, State<PlayerStateEnum> superFSM, StateFactory<PlayerStateEnum> factory) : base(controller, stateName, superFSM, factory) {
		AddConditionToSelf(() => !IsZero(_controller.XInput) && _controller.TickInput && _controller.DownInput);

		//AddNewTransition(,)
	}

	public override void Enter() {
		_controller.StateData.CanChangeDir = false;
		_controller.Velocity = UnityEngine.Vector2.zero;
		AudioManager.Play(_controller.StateAudio, AudioStr.AirTickAudio);
		_controller.PlayAnim(PlayerStateEnum.AirTickBegin);
		_loopAnimStart = false;
		_controller.SetGravity(0);
	}

	public override void Update() {


		if (!_loopAnimStart && _controller.IsAnimPlayOver()) {
			_loopAnimStart = true;
			var dir = _controller.StateData.FaceDir;
			var v = _controller.ConfigData.AirTickSpeed;
			_controller.PlayAnim(PlayerStateEnum.AirTickLoop);
			_controller.Velocity = new UnityEngine.Vector2(dir * v.x, v.y);
			//Debug.Log($"{dir}, {v.x}");
			_controller.ResetGravity();
		}
		//else if (_loopAnimStart && ) {

		//}
		base.Update();
	}

	public override void Exit() {
		_controller.StateData.CanChangeDir = true;
		_controller.ResetGravity();
	}
}